home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / D-G / FORTRAN Goodies / String Utilities / invert.f < prev    next >
Encoding:
Text File  |  1990-12-05  |  1.1 KB  |  66 lines  |  [TEXT/MPS ]

  1. c
  2. c    This example inverts a string.
  3. c
  4. c      Function INVERT
  5. c        Takes a string argument.
  6. c        Returns the argument with the letters in the reverse order.
  7. c
  8. c
  9. c    Example provided for owners of Language Systems FORTRAN
  10. c    © 1990 Language Systems Corp.
  11. c
  12. c    Written by Steven Hopkins
  13. c
  14.     string function INVERT(StrArg)
  15.     implicit none
  16.  
  17. C        receive the argument by Descriptor
  18.  
  19.     structure /DescRec/
  20.         pointer /character*1/ DataPtr
  21.         integer*2 DataSize
  22.         integer*2 SymT
  23.     end structure
  24.     record /DescRec/ StrArg
  25.  
  26. C        local declarations
  27.  
  28.     string        result
  29.     integer*4    limit,len
  30.     pointer     /byte/ strptr, argptr
  31.  
  32. C        set up pointer to the string argument
  33.  
  34.     argptr = StrArg.DataPtr
  35.  
  36. C        read the current length
  37.  
  38.     len = argptr^
  39.     
  40. C        set up pointer to the local result variable
  41.  
  42.     strptr = %loc(result)
  43.  
  44. C        copy the length byte into the result
  45.  
  46.     strptr^ = argptr^
  47.     strptr = strptr + 1
  48.  
  49. C        point to the end of the argument
  50.  
  51.     argptr = argptr + len
  52.  
  53. C        store the argument character by character into the
  54. C        local string
  55.  
  56.     limit = %loc(result) + len
  57.     do while (strptr <= limit)
  58.         strptr^ = argptr^
  59.         argptr = argptr - 1
  60.         strptr = strptr + 1
  61.     end do
  62.  
  63. C        return the inverted string
  64.  
  65.     invert = result
  66.     end